<template>
	<view class="box">
		<view class="" style="font-size: 30rpx;margin-bottom: 20rpx;">
			商家收货地址
		</view>
		<view class="addressBox">
			<view class="addressBox-input">
				<view class="" style="margin-bottom: 10rpx;">
					{{orderDeatil.details.config.contact_name|| ''}} {{orderDeatil.details.config.contact_mobile|| ''}}
				</view>
				<view class="">
					{{orderDeatil.details.config.contact_address || ''}}
				</view>
			</view>
			<view class="copy-btn" style="font-size: 24rpx;" @click="onCopy()">
				复制
			</view>
		</view>

		<!-- 	<view class="" style="margin: 20rpx 0;">
			<u-input v-model="value" :type="type" :border="border" placeholder='请输入快递公司名称' />
		</view> -->
		<view class=""
			style="margin: 20rpx 0;width: 100%;border: 1rpx solid gainsboro;padding: 10rpx 20rpx;color: #c2c6cd;font-size: 28rpx;border-radius: 10rpx;display: flex;justify-content: space-between;">
			<input type="text" v-model="value" placeholder="请输入快递公司名称" style="font-size: 24rpx !important;">
			<view class="copy-btn" style="font-size: 24rpx;" @click="inputFn()">
				搜索
			</view>
		</view>
		<view class="popshow" v-if="popshow">
			<view class="popshowList">
				<view class="popshowList-item" v-for="(item,index) in expressList" :key="item.id"
					@click="selectExpress(item)">
					{{item.name}}
				</view>
			</view>
			<view class="" v-if="expressList.length == 0"
				style="display: flex;justify-content: center;align-items: center;height: 100%;padding: 10rpx;">
				暂无数据~
			</view>
		</view>

		<view class=""
			style="margin: 20rpx 0;width: 100%;border: 1rpx solid gainsboro;padding: 10rpx 20rpx;color: #c2c6cd;font-size: 28rpx;border-radius: 10rpx;">
			<input type="text" v-model="value1" placeholder="请输入寄回商品快递单号" style="font-size: 24rpx !important;">
		</view>

		<view class="" style="font-size: 28rpx;margin:20rpx 0;">
			请上传快递标签照片
		</view>

		<view class="" style="margin-top: 20rpx;margin-bottom: 20rpx;">
			<image :src="$BASE_URL + piclist[3]" mode="aspectFill" style="width: 148rpx;height: 148rpx;"
				@click="selectPic()" v-if="imgurl== ''">
			</image>
			<image :src="$BASE_URL + imgurl" mode="aspectFill" style="width: 148rpx;height: 148rpx;"
				@click="selectPic()" v-if="imgurl != ''">
			</image>
		</view>
		<view class="" style="font-size: 24rpx;color: #999999;">
			*快递单信息需可清晰辨认
		</view>
		<view class="" style="display: flex;justify-content: right;">
			<view class="send-btn" @click="sendGoods()">
				寄回商品
			</view>
		</view>
		<u-select v-model="show" :list="list" @confirm='confirm'></u-select>
	</view>
</template>

<script>
	export default {
		props: {
			orderId: {
				type: Number,
				default: 0
			},
			orderDeatil: {
				type: Object,
				default: () => {
					return {}
				}
			}
		},
		data() {
			return {
				popshow: false, // 列表显示
				show: false,
				value: '',
				value1: '',
				type: 'text',
				type1: 'text',
				border: true,
				border1: true,
				piclist: [],
				list: [{
						value: '1',
						label: '江'
					},
					{
						value: '2',
						label: '湖'
					}
				],
				imgurl: '',
				timer: null,
				expressList: [],
				expressId: '',
			}
		},
		mounted() {
			this.getPic()
			setTimeout(() => {
				console.log(this.orderDeatil);
			}, 1500)
		},
		methods: {
			onCopy(code) {
				let that = this;
				uni.setClipboardData({
					data: this.orderDeatil.details.config.contact_name + ',' + this.orderDeatil.details.config
						.contact_mobile + ',' + this.orderDeatil.details.config.contact_address,
					success: function(data) {
						that.$u.toast('已复制到剪切板');
					}
				});
			},
		
			// 寄回商品
			sendGoods() {
				if (this.expressId == '') {
					uni.showToast({
						title: '请搜索后选择快递',
						icon: 'none'
					})
					return false
				}
				if (this.value1 == '') {
					uni.showToast({
						title: '请填写寄回快递单号',
						icon: 'none'
					})
					return false
				}
				if (this.imgurl == '') {
					uni.showToast({
						title: '请上传寄回快递单图片',
						icon: 'none'
					})
					return false
				}
				this.$http('store.orderReplay', {
					shopro_order_id: this.orderId, //订单id
					express_id: this.expressId, //快递id
					express_no: this.value1, //快递单号
					images: this.imgurl, //图片
					address:this.orderDeatil.details.config.contact_address,
					name:this.orderDeatil.details.config.contact_name,
					mobile:this.orderDeatil.details.config.contact_mobile,
				}).then(res => {
					// console.log(res);
					uni.navigateBack()
				})
			},
			selectExpress(item) {
				this.value = item.name
				this.expressId = item.id
				this.popshow = false
			},
			inputFn(e) {
				// console.log(e);
				if (this.value.trim() == '') {
					return false
				}
				this.popshow = true
				this.$http('store.orderList', {
					name: this.value
				}).then(res => {
					// console.log(res, 'res');
					if (res.code == 1) {
						this.expressList = res.data.list.data
					}
				})
			},
			// 选择头像
			selectPic() {
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album', 'camera'], //从相册选择
					success: (res) => {
						uni.uploadFile({
							url: 'https://zuji.jiusuding.cn/api/common/upload', //仅为示例，非真实的接口地址
							filePath: res.tempFilePaths[0],
							fileType: 'image',
							name: 'file',
							header: {
								"Content-Type": "multipart/form-data",
								"token": uni.getStorageSync('token') || ''
							},
							success: (uploadFileRes) => {
								// console.log(JSON.parse(uploadFileRes.data).data.url);
								this.imgurl = JSON.parse(uploadFileRes.data).data.url
							}
						});
					}
				});


			},
			confirm(e) {
				// console.log(e);
				this.value = e[0].label
			},
			getPic() {
				this.$http('common.getPic', {}).then(res => {
					if (res.code === 1) {
						this.piclist = res.data.result.shopInIcon
					}
				});
			}
		}
	}
</script>

<style scoped lang="scss">
	.box {
		padding: 20rpx;
		width: 710rpx;
		border-radius: 20rpx;
		background-color: #fff;
		margin: 20rpx auto;

		.addressBox {
			display: flex;
			align-items: center;
			justify-content: space-between;
			border-radius: 20rpx;

			.addressBox-input {
				border-radius: 20rpx;
				width: 512rpx;
				padding: 14rpx;
				font-size: 24rpx;
				background-color: #fafafa;
			}

			.copy-btn {
				border: 2rpx solid #999;
				border-radius: 30rpx;
				text-align: center;
				line-height: 52rpx;
				width: 100rpx;
				height: 52rpx;
				color: #999;
			}

			.copy-btn:active {
				background-color: #eeeeee;
				color: white;
			}

		}

		.send-btn {
			width: 180rpx;
			height: 60rpx;
			line-height: 60rpx;
			text-align: center;
			border-radius: 100rpx;
			opacity: 1;
			font-size: 24rpx;
			color: #FF4747;
			box-sizing: border-box;
			border: 2rpx solid #FF4747;
		}

		.send-btn:active {
			background-color: #FF4747;
			color: white;
		}

		.copy-btn {
			border: 2rpx solid #999;
			border-radius: 30rpx;
			text-align: center;
			line-height: 52rpx;
			width: 100rpx;
			height: 52rpx;
			color: #999;
		}

		.copy-btn:active {
			background-color: #eeeeee;
			color: white;
		}

		.popshow {
			width: 100%;
			min-height: 80rpx;
			background-color: #fff;
			border-radius: 10rpx;
			padding: 10rpx;
			box-sizing: border-box;
			box-shadow: 0px 0px 8rpx 0rpx rgba(77, 23, 17, 0.2);

			.popshowList {
				max-height: 300rpx;
				padding: 0 20rpx;

				.popshowList-item {
					border-radius: 10rpx;
					padding: 20rpx 20rpx;
					border-bottom: 1rpx solid #ebebeb;

				}

				.popshowList-item:active {
					background-color: #ebebeb;
				}
			}
		}
	}
</style>
